package Day005_API02.ZuoYe;

import java.math.BigDecimal;

public class Test1 {
    public static void main(String[] args) {

        double[] arr = {0.1, 0.2, 2.1, 3.2, 5.56, 7.21};
        double sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        System.out.println("总值:" + sum); // 18.37

        BigDecimal b1 = new BigDecimal(sum);
        BigDecimal b2 = new BigDecimal(arr.length);
        BigDecimal b3 = b1.divide(b2,2,BigDecimal.ROUND_HALF_UP);
        System.out.println("平均值:" + b3); // 3.06
    }
}
